package com.medicine.product.utils;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lynn
 * @version 1.0
 * @date 2022/1/20
 */
public class ThreadLocalOOM {

    /**
     * 测试线程池
     */
    private static Executor threadPool = new ThreadPoolExecutor(3, 3, 40,
            TimeUnit.SECONDS, new LinkedBlockingDeque<>());


    static class Info {
        private byte[] info = new byte[10 * 1024 * 1024];
    }

    private  static ThreadLocal<Info> infoThreadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            threadPool.execute(() -> {
                infoThreadLocal.set(new Info());
                System.out.println("Thread started:" + Thread.currentThread().getName());
            });
            Thread.sleep(100);
        }

    }
}
